package tests;

import common.Utils;
import org.junit.jupiter.api.Assertions;
import org.openqa.selenium.By;

public class PersonalList extends Utils {

    private static String url = "http://8.134.99.135:58080/index.html";

    public PersonalList() {
        super(url);
    }

    //未登录状态，直接跳回登录页面
    public void noLogin() {
        String currentUrl = driver.getCurrentUrl();
        Assertions.assertEquals("http://8.134.99.135:58080/sign-in.html", currentUrl);
    }

    //登录状态，检查页面是否正常加载
    public void loginSuc(){
        driver.findElement(By.cssSelector("#index_nav_avatar")).click();
        driver.findElement(By.cssSelector("#index_user_profile")).click();

        //头部的个人信息
        driver.findElement(By.cssSelector("#profile_avatar"));
        String nickName = driver.findElement(By.cssSelector("#profile_nickname")).getText();
        Assertions.assertEquals("test666",nickName);
        //发帖数
        String numberText = driver.findElement(By.cssSelector("#bit-forum-content > div.page-header.d-print-none > div" +
                " > div > div.col > div > div:nth-child(1)")).getText();
        Assertions.assertTrue(numberText.contains("发贴数: "));

        //邮箱
        String emailText = driver.findElement(By.cssSelector("#bit-forum-content > div.page-header.d-print-none >" +
                " div > div > div.col > div > div:nth-child(2)")).getText();
        Assertions.assertTrue(emailText.contains("邮箱:"));

        //注册日期
        String timeText = driver.findElement(By.cssSelector("#bit-forum-content > div.page-header.d-print-none >" +
                " div > div > div.col > div > div:nth-child(3)")).getText();
        Assertions.assertTrue(timeText.contains("注册日期:"));

        //帖子列表
        driver.findElement(By.cssSelector("#bit-forum-content > div.page-body > div > div"));

        //检查其中一篇帖子是否正确加载
        String title = driver.findElement(By.cssSelector("#profile_article_body > li:nth-child(1) > " +
                "div.card.timeline-event-card > div > div > div > div " +
                "> div.text-truncate > a > strong")).getText();
        Assertions.assertEquals("测试发布帖子",title);
        driver.findElement(By.cssSelector("#profile_article_body > li:nth-child(1) > div.card.timeline-event-card > " +
                "div > div > div > div > div.text-muted.mt-2 > div > div.col > ul > li > svg"));
        String time = driver.findElement(By.cssSelector("#profile_article_body > li:nth-child(1) > div.card.timeline" +
                "-event-card >div > div > div > div > div.text-muted.mt-2 > div > div.col > ul > li")).getText();
        Assertions.assertNotNull(time);
        driver.findElement(By.cssSelector("#profile_article_body > li:nth-child(1) > div.card.timeline-event-card >" +
                " div > div > div > div > div.text-muted.mt-2 > div > div.col-auto.d-none.d-md-inline " +
                "> ul > li:nth-child(1) > svg"));
        String lookText = driver.findElement(By.cssSelector("#profile_article_body >li:nth-child(1)>div.card.timeline" +
                "-event-card > div > div > div > div > div.text-muted.mt-2 > div > div.col-auto.d-none." +
                "d-md-inline > ul > li:nth-child(1)")).getText();
        Assertions.assertNotNull(lookText);
        driver.findElement(By.cssSelector("#profile_article_body > li:nth-child(1) > div.card.timeline-event-card > " +
                "div > div > div > div > div.text-muted.mt-2 >div > div.col" +
                "-auto.d-none.d-md-inline > ul > li:nth-child(2) > svg"));
        String likeNum = driver.findElement(By.cssSelector("#profile_article_body > li:nth-child(1) > div.card." +
                "timeline-event-card >div > div > div > div > div.text-muted.mt-2 > div > div.col-auto." +
                "d-none.d-md-inline > ul > li:nth-child(2)")).getText();
        Assertions.assertNotNull(likeNum);
        driver.findElement(By.cssSelector("#profile_article_body > li:nth-child(1) > div.card." +
                "timeline-event-card > div > div > div > div > div.text-muted.mt-2 > div > div.col-auto.d-none." +
                "d-md-inline > ul > li:nth-child(3) > svg > path:nth-child(2)"));
        String replyNum = driver.findElement(By.cssSelector("#profile_article_body > li:nth-child(1) > div.card" +
                ".timeline-event-card > div > div > div > div > div.text-muted.mt-2 > div > div.col-auto.d-none." +
                "d-md-inline > ul > li:nth-child(3)")).getText();
        Assertions.assertNotNull(replyNum);

        //个人简介
        String introduceTitle = driver.findElement(By.cssSelector("#bit-forum-content > div.page-body > div > div " +
                "> div.col-lg-4 > div > div > div > div > h2")).getText();
        Assertions.assertEquals("个人介绍",introduceTitle);
        String introduceText = driver.findElement(By.cssSelector("#profile_remark")).getText();
        Assertions.assertEquals("一步一个脚印",introduceText);
    }
}
